<template>
  <div class="app-container">
    <el-row :gutter="20">
      <!--部门数据-->

      <!--用户数据-->
      <el-col :span="24" :xs="24">
        <el-form
          :model="queryParams"
          style="flex"
          ref="queryForm"
          size="small"
          :inline="true"
          label-width="68px"
        >
          <el-form-item label="姓名" prop="name">
            <el-input
              v-model="queryParams.name"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item>
            <el-button
              type="primary"
              icon="el-icon-search"
              size="mini"
              @click="handleQuery"
              >搜索</el-button
            >
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
              >重置</el-button
            >
          </el-form-item>
        </el-form>

        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button
              type="primary"
              plain
              icon="el-icon-plus"
              size="mini"
              @click="handleAdd"
              >新增</el-button
            >
          </el-col>
          <!-- <el-col :span="1.5">
            <el-button
              type="success"
              plain
              icon="el-icon-edit"
              size="mini"
              :disabled="single"
              @click="handleUpdate"
              >修改</el-button
            >
          </el-col> -->
          <!-- <el-col :span="1.5">
            <el-button
              type="danger"
              plain
              icon="el-icon-delete"
              size="mini"
              :disabled="multiple"
              @click="handleDelete"
              v-hasPermi="['system:user:remove']"
              >删除</el-button
            >
          </el-col> -->
        </el-row>

        <el-table
          v-loading="loading"
          :data="tableData"
          stripe
          border
          size="small"
          @selection-change="handleSelectionChange"
        >
          <!-- <el-table-column type="selection" width="50" align="center" /> -->

          <el-table-column label="分类" key="cate" prop="cate"> </el-table-column>
          <el-table-column label="名称" key="name" prop="name"> </el-table-column>
          <el-table-column label="code" key="code" prop="code" />
          <el-table-column label="学分" key="classhour" prop="classhour" />

          <el-table-column
            label="备注"
            align="center"
            key="snote"
            prop="snote"
            :show-overflow-tooltip="true"
          />
          <el-table-column
            label="操作"
            align="center"
            width="160"
            class-name="small-padding fixed-width"
          >
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                icon="el-icon-edit"
                @click="handleUpdate(scope.row)"
                >修改</el-button
              >
            </template>
          </el-table-column>
        </el-table>

        <pagination
          v-show="total > 0"
          :total="total"
          :page.sync="queryParams.page"
          :limit.sync="queryParams.size"
          @pagination="getList"
        />
      </el-col>
    </el-row>

    <coursedialog ref="coursedialog"></coursedialog>
  </div>
</template>

<script>
import { courseService } from "@/api/dormService";

import coursedialog from "./coursedialog.vue";

export default {
  name: "course",
  dicts: [],
  components: { coursedialog },
  data() {
    return {
      sexOptions: [],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 用户表格数据
      tableData: null,
      // 弹出层标题
      title: "",
      // 部门树选项
      deptOptions: undefined,
      // 是否显示弹出层

      // 部门名称
      deptName: undefined,
      // 默认密码
      initPassword: undefined,
      // 日期范围
      dateRange: [],
      // 岗位选项
      postOptions: [],
      // 角色选项
      roleOptions: [],

      defaultProps: {
        children: "children",
        label: "label",
      },

      // 查询参数
      queryParams: {
        page: 1,
        size: 10,
        customerName: undefined,
        phone: undefined,
        status: undefined,
        deptId: undefined,
      },
    };
  },

  created() {
    this.getList();
    this.sexOptions = this.$dict.get("sex");
    console.error(this.sexOptions, "1111");
    // this.getDeptTree();
    // this.getConfigKey("sys.user.initPassword").then(response => {
    //   this.initPassword = response.msg;
    // });
  },
  methods: {
    handleStateChange({ id }) {
      ctypeService.postStateChange({ id });
    },
    /** 查询用户列表 */
    getList() {
      this.loading = true;
      courseService.list(this.queryParams).then((response) => {
        this.tableData = response.data.data;
        this.total = response.data.total;
        this.loading = false;
      });
    },

    // 表单重置
    reset() {
      this.form = {
        userId: undefined,
        deptId: undefined,
        username: undefined,
        nickName: undefined,
        password: undefined,
        phone: undefined,
        email: undefined,
        sex: undefined,
        status: "0",
        remark: undefined,
        postIds: [],
        roleIds: [],
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.page = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.userId);
      this.single = selection.length != 1;
      this.multiple = !selection.length;
    },

    /** 新增按钮操作 */
    handleAdd() {
      this.$refs.coursedialog.open().then(() => {
        this.getList();
      });
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      let data = JSON.parse(JSON.stringify(row));
      this.$refs.coursedialog.open(data).then(() => {
        this.getList();
      });
    },
  },
};
</script>

<style scoped></style>
